package com.elastic.test;

import com.elastic.model.Product;
import com.elastic.util.MyDataSource;
import com.jfinal.plugin.activerecord.Db;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: 李德才
 * @description:
 * @create: 2021-04-05 16:24
 **/
public class DataForMySql {
    static {
        new MyDataSource();
    }

    public static void main(String[] args) {
        insertData();
//        System.err.println( getList());
    }

    public static List<Product> getList() {
        return Product.dao.findAll();
    }

    public static Product findById(Integer id) {
        return Product.dao.findById(id);
    }

    public static void insertData() {
        List<Product> productList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Product product = new Product();
            product.setName("小米手机"+i);
            product.setDesc("性价比手机");
            product.setTags("发烧,陶瓷,高级,简约,时尚");
            product.setCreatetime(new Date());
            productList.add(product);
        }
        Db.batchSave(productList, 10);
    }
}
